<template>
	<view :class="[primarySize()]">
		<view class="page-foot bg-white">
			<view class="ptb10 plr30" @click="bindEditJobIntention()">
				<view class="btn3">+新增求职意向</view>
			</view>
		</view>
		<view class="container bg-white">
			<view class="plr30 pb30 pt10">
				<view class="item flex-box" v-for="(item,index) in job_intentions" @click="bindEditJobIntention(item)">
					<view class="flex-grow-1">
						<view class="fs36 fwb col3 lh50">{{item.fav_category.category_name}}</view>
						<view class="gongzi">{{item.expect_salary.name}}</view>
						<view class="flex-box flex-wrap">
							<view class="job_label">{{item.job_type_text}}</view>
							<view class="job_label">{{item.fav_city?item.fav_city.name:''}}</view>
							<view class="job_label">{{item.fav_industry?item.fav_industry.name:''}}</view>
						</view>
					</view>
					<image src="@/static/public/arrow-r.png" mode="widthFix" class="ico13"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {

				job_intentions: []
			}
		},
		onReady() {
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: this.primaryColor()
			})
		},
		onLoad() {

			this.fetchJobIntentions();
		},
		methods: {
			fetchJobIntentions() {
				this.$core.get({
					url: 'xilujob.resume/job_intention',
					data: {},
					success: ret => {
						this.job_intentions = ret.data
					}
				});
			},
			//求职意向
			bindEditJobIntention(model) {
				uni.navigateTo({
					url: '/pages/user/job_interest',
					events: {
						dataTransfer: data => {
							let job_intention = data.model,
								index = null,
								job_intentions = this.job_intentions;
							for (let i = 0; i < job_intentions.length; i++) {
								if (job_intentions[i].id == job_intention.id) {
									index = i;
									break;
								}
							}
							if (index === null) {
								job_intentions.push(job_intention);
							} else {
								job_intentions.splice(index, 1, job_intention);
							}
							job_intentions.sort((a, b) => {
								return a.start > b.start ? -1 : 1;
							});
							this.job_intentions = job_intentions;
							uni.$emit(app.globalData.Events.UcenterInfoCompleteChange, data.complete_percent);
						},
						dataDelTransfer: data => {
							let job_intention = data.model,
								index = null,
								job_intentions = this.job_intentions;
							for (let i = 0; i < job_intentions.length; i++) {
								if (job_intentions[i].id == job_intention.id) {
									index = i;
									break;
								}
							}
							job_intentions.splice(index, 1);
							job_intentions.sort((a, b) => {
								return a.start > b.start ? -1 : 1;
							});
							this.job_intentions = job_intentions;
							uni.$emit(app.globalData.Events.UcenterInfoCompleteChange, data.complete_percent);
						}
					},
					success: res => {
						res.eventChannel.emit('dataTransfer', {
							model: model || {}
						});
					}
				});
			},

		}
	}
</script>

<style lang="scss" scoped>
	.page-head {
		height: 165rpx;
		width: 100%;
		background: var(--primary);

		.lh66 {
			line-height: 66rpx;
		}
	}

	.pt165 {
		padding-top: 165rpx;
	}

	.item {
		width: 692rpx;
		padding: 30rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(0, 0, 0, 0.03);
		border-radius: 18rpx;
		margin-top: 20rpx;
		border: 1px solid #EBEBEB;

		.ico13 {
			width: 13rpx;
		}
	}

	.btn3 {
		border-radius: 40rpx;
	}
	.gongzi {
	    font-size: 30rpx;
	    font-weight: bold;
	    color: #F5584F;
	    line-height: 42rpx;
	}
	
	.job_label {
	    margin: 15rpx 15rpx 0 0;
	    padding: 0 18rpx;
	    height: 40rpx;
	    background: #F7F7F7;
	    border-radius: 8rpx;
	    font-size: 20rpx;
	    color: #999999;
	    line-height: 40rpx;
	    text-align: center;
	}

</style>